package com.example.demo;

import io.micrometer.core.instrument.Counter;
import io.micrometer.core.instrument.MeterRegistry;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author lizhien (zhien.li@nascent.cn)
 * @version 1.0.0
 * @date 2022/3/18 16:02
 * @description com.example.demo
 */

@SpringBootApplication
@RestController
public class PrometheusApplication {

    public static void main(String[] args) {
        SpringApplication.run(PrometheusApplication.class, args);
    }

    @GetMapping("/")
    public String index() {
        return "hello prometheus";
    }

    private Counter counter;

    public PrometheusApplication(MeterRegistry meterRegistry) {
        this.counter = meterRegistry.counter("greeting");
    }

    @RequestMapping(value = "/test", method = RequestMethod.GET)
    public String test() {
        this.counter.increment();
        return "hello world #" + this.counter.count();
    }

}
